﻿package com.wandian.view.mediator.account
{
	import com.wandian.controller.AccountCommand;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.InRoomPlayerDataProxy;
	import com.wandian.model.SwfDataProxy;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.GolbalTimer;
	import com.wandian.view.components.ui.AddBtn;
	import com.wandian.view.components.ui.MaskTipPanel;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.*;

	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class AccountMediator extends Mediator
	{
		private var _tabBar:CLZTabBar;
		private var _strInitShowType:String;
		private var _playerVo:PlayerVo;
		private var _global:GameData;
		private var _minType:String;
		public static const NAME:String="Accountdiator";

		public function AccountMediator(viewComponent:Object, strInitShowType:String, playerVo:PlayerVo, minType:String="")
		{
			this._global=GameData.getInstance();
			this._strInitShowType=strInitShowType;
			this._playerVo=playerVo;
			this._minType=minType;
			super(NAME, viewComponent);
			return;
		} 

		override public function onRegister():void
		{
			this.mcAccount.title_txt.htmlText=GameData.tip["PALYER_INFO_NAME"];//个人信息
			facade.registerCommand(CLZNoticeName.MY_PROP_LIST_REQ, AccountCommand);
			facade.registerCommand(CLZNoticeName.MY_HONOR_REQ, AccountCommand);
			facade.registerCommand(CLZNoticeName.WEALTH_RECORD_REQ, AccountCommand);
			facade.registerCommand(CLZNoticeName.PLAYER_INFOMATION_REQ, AccountCommand);
			AddBtn.initBtn(this.mcAccount, CLZNoticeName.HIDE_ACCOUNT, AddBtn.CLOSE_TWO, "", 4, 1);
			if (this._playerVo.userid != this._global.userInfo.userVo.userid)
			{
				this.mcAccount.propGift_btn.visible=false;
				this.mcAccount.record_btn.visible=false;
			}
			//个人概况,道具礼品,成就,充值记录
//			var tabs:Array=[[this.mcAccount.information_btn, GameData.tip["INFORMATION_BTN"]], [this.mcAccount.propGift_btn, GameData.tip["PROPGIFT_BTN"]], [this.mcAccount.achievement_btn, GameData.tip["ACHIEVEMENT_BTN"]], [this.mcAccount.record_btn, GameData.tip["COIN_RECORD"]]];
			var tabs:Array=[[this.mcAccount.information_btn, GameData.tip["INFORMATION_BTN"]]];
			this.mcAccount.propGift_btn.visible=false;
			this.mcAccount.achievement_btn.visible=false;
			this.mcAccount.record_btn.visible=false;
			this._tabBar=new CLZTabBar(tabs);
			var index:int=0;
			while (index < tabs.length)
			{

				tabs[index][0].addEventListener(Event.CHANGE, this.changeTabBarHandler);
				index=index + 1;
			}
			switch (this._strInitShowType)
			{
				case CLZNoticeName.ACHIEVEMENT_BTN:
				{
					this._tabBar.setClickIndex(this.mcAccount.achievement_btn);
					break;
				}
				case CLZNoticeName.USEPROPS_BTN:
				{
					this._tabBar.setClickIndex(this.mcAccount.propGift_btn);
					break;
				}
				case CLZNoticeName.SHOW_ACCOUNT:
				{
					this._tabBar.setClickIndex(this.mcAccount.information_btn);
					break;
				}
				default:
				{
					break;
				}
			}
			return;
		} 

		private function changeTabBarHandler(event:Event):void
		{
			var mc:MovieClip=null;
			this.removeAll();
			switch (event.target.name)
			{
				case "information_btn":
				{
					mc=GameData.getMovieClip("InformationMc");
					facade.registerMediator(new InfomationMediator(mc, this._playerVo));
					break;
				}
				case "propGift_btn":
				{
					mc=GameData.getMovieClip("PropGiftMc");
					facade.registerMediator(new PropGiftMediator(mc, this._minType));
					break;
				}
				case "achievement_btn":
				{
					mc=GameData.getMovieClip("AchievementMc");
					facade.registerMediator(new HonorMediator(mc, this._playerVo));
					break;
				}
				case "record_btn":
				{
					mc=GameData.getMovieClip("RecordMc");
					facade.registerMediator(new RecordMediator(mc));
					break;
				}
				default:
				{
					break;
				}
			}
			this.mcAccount.conten_mc.addChild(mc);
			mc.x=0;
			mc.y=0;
			return;
		} 

		private function removeAll():void
		{
			var child:*=undefined;
			facade.sendNotification(CLZNoticeName.CHANGE_ACCOUNT);
			facade.removeMediator(InfomationMediator.NAME);
			facade.removeMediator(PropGiftMediator.NAME);
			facade.removeMediator(HonorMediator.NAME);
			facade.removeMediator(RecordMediator.NAME);
			while (this.mcAccount.conten_mc.numChildren)
			{

				child=this.mcAccount.conten_mc.removeChildAt(0);
				child=null;
			}
			return;
		} 

		override public function listNotificationInterests():Array
		{
			return [CLZNoticeName.HIDE_ACCOUNT];
		} 

		override public function handleNotification(param1:INotification):void
		{
			switch (param1.getName())
			{
				case CLZNoticeName.HIDE_ACCOUNT:
				{
					if (Texas.I._mcWindosView.contains(this.mcAccount))
					{
						Texas.I._mcWindosView.removeChildTo(this.mcAccount);
						viewComponent=null;
					}
					facade.removeCommand(CLZNoticeName.MY_PROP_LIST_REQ);
					facade.removeCommand(CLZNoticeName.MY_HONOR_REQ);
					facade.removeMediator(AccountMediator.NAME);
					facade.removeCommand(CLZNoticeName.WEALTH_RECORD_REQ);
					break;
				}
				default:
				{
					break;
				}
			}
			return;
		} 

		private function get mcAccount():MovieClip
		{
			return viewComponent as MovieClip;
		} 

	}
}
